---
--类名: UiHandler.lua
--创建日期: 2016-11-4
--创建人: 陈小虎
--功能描述:
--修改内容:
--修改日期:
--修改人:
--修改备注:
--

local PopupUI = import(".PopupUI")
local SystemUI = import(".SystemUI")
local DesktopModel = require("app.system.desktop.desk.models.DesktopModel")

local CCNode_setVisible = cc.Node.setVisible
local CCNode_isVisible = cc.Node.isVisible
local CCNode_getChildByName = cc.Node.getChildByName
local CCNode_addChild = cc.Node.addChild
local CCNode_removeChildByName = cc.Node.removeChildByName

local UiHandler = class("UiHandler")

function UiHandler:ctor()
    cc(self):addComponent("components.behavior.EventProtocol"):exportMethods()

    self.m_thirdTipsDataList = {} -- 桌面右上角提示数据列表
    self._indicatorCron = nil -- 繁忙转圈延迟回调

    self._isInit = false
end

function UiHandler:isInit()
    return self._isInit
end

-------------------- DesktopModel 功能开放 start -------------------
function UiHandler:getDesktopModel()
    return self._desktopModel
end

-- 移除功能，适用于按时开放／取消的功能
function UiHandler:removeOpenFunctionId(funcId)
    local ret = self._desktopModel:removeFuncId(funcId)

    if ret then
        self._desktopController:refreshNewFunction()
    end
end

-- 添加功能，适用于按时开放／取消的功能
-- ignoreGuide, 是否跳过引导动画
function UiHandler:addOpenFunctionId(funcId, iconPathData, ignoreGuide)
    local ret = self._desktopModel:addFuncId(funcId, true, iconPathData, ignoreGuide)

    if ret then
        self._desktopController:refreshNewFunction({funcId})
    end
end

function UiHandler:isFunctionOpen(funcId)
    funcId = tonumber(funcId)
    return self._desktopModel:isFuncOpen(funcId)
end

function UiHandler:getFunctionOpenCondition(funcId)
    return self._desktopModel:getFunctionOpenCondition(funcId)
end


-- 移除快捷方式
function UiHandler:removeDesktopFunctionId(funcId)
    local ret = self._desktopModel:removeDesktopFuncId(funcId)
    if ret then
        self._desktopController:refreshNewFunction({funcId})
    end
end

function UiHandler:addDesktopFunctionId(funcId, isNew, iconPathData)
    local ret = self._desktopModel:addDesktopFuncId(funcId, isNew, iconPathData)
    if ret then
        self._desktopController:refreshNewFunction({funcId})
    end
end

-------------------- DesktopModel 功能开放 end --------------------

function UiHandler:setUiParent(uiParent)
    self.m_uiParent = uiParent
end

function UiHandler:getUiParent()
    return self.m_uiParent
end

function UiHandler:getSystemUi()
    return self.m_systemUi
end

function UiHandler:getStoryModeUi()
    return self.m_storyModeUi
end

function UiHandler:getPopupUi()
    return self.m_popupUi
end

function UiHandler:initSceneTopLayer()
   self.m_sceneTopLayer = display.newLayer()
   app.scene:addChild(self.m_sceneTopLayer, 9999)

   self.m_popDialogUI = display.newLayer()
   self.m_sceneTopLayer:addChild(self.m_popDialogUI,SceneZOrder.dialogZOrder)

   self.m_toastUI = display.newLayer()
   self.m_sceneTopLayer:addChild(self.m_toastUI,SceneZOrder.toastZOrder)
   display.setToastParent(self.m_toastUI)

   -- self._indicatorView  = display.newActivityIndicator()
   -- self:addPopDialog(self._indicatorView, 2, true)
end

function UiHandler:showIndicator(b)
    local view = self._indicatorView
    if not view then
        view = display.newActivityIndicator()
        self:addPopDialog(view, 2, true)
        view:setVisible(false)
        self._indicatorView = view
    end

    if CCNode_isVisible(view) == b then
        return
    end

    view:setVisible(b)

    if b then
        -- 显示的都延迟0.5秒，避免时间太短闪一下
        self._indicatorCron = scheduler.newCron(function()
            self._indicatorCron = nil
            view:play()
        end, 0.5)
    else
        if self._indicatorCron then
            scheduler.cancelCron(self._indicatorCron)
            self._indicatorCron = nil
        end
        view:stop()
    end
end

function UiHandler:displayConnecterStateUI(b)
    local connecterStateUI = self._connecterStateUI
    if connecterStateUI then
        local isVisible = CCNode_isVisible(connecterStateUI)
        if b == isVisible then
            return
        end
        CCNode_setVisible(connecterStateUI,b)
        local timeline = connecterStateUI:getActionByTag(0)
        if b then
            timeline:gotoFrameAndPlay(0,true)
        else
            timeline:gotoFrameAndPause(0)
        end
    end
end

-- 添加最顶层弹框
-- node       添加的node
-- zOrder     层级，默认不填（重连弹框 = 1， indicatorView = 2， 退出登录框 = 10000）
-- notDelete  不能通过clearPopDialog清除，需要主动清楚，设置tag=100
function UiHandler:addPopDialog(node,zOrder,notDelete)
    if cc.isDead(node) then return end
    self.m_popDialogUI:addChild(node, zOrder or 0)

    if notDelete then
        node:setTag(100)
    end
end

function UiHandler:clearPopDialog()
    local popDialogUI = self.m_popDialogUI
    local children = popDialogUI:getChildren()
    for _,child in pairs(children) do
        if child:getTag() ~= 100 then
            popDialogUI:removeChild(child)
        end
    end
end

function UiHandler:init()
    self.m_imBubbleUi = cc.Node:create()
    self.m_uiParent:addChild(self.m_imBubbleUi,SceneZOrder.imBubbleZOrder)

    self.m_systemUi = SystemUI.new()
    self.m_uiParent:addChild(self.m_systemUi,SceneZOrder.systemUIZOrder)
    self.m_systemUi:setEmptyCB(function()
        self:postDesktopState()
        --self:checkPayNotice()
        self:checkDesktopGuide()
    end)

    self.m_storyModeUi = PopupUI.new()
    self.m_storyModeUi:setName("StoryModeUIManager")
    self.m_uiParent:addChild(self.m_storyModeUi,SceneZOrder.storyModeUIOperateZOrder)
    self.m_storyModeUi:setEmptyCB(function()
        self:postDesktopState()
        --self:checkPayNotice()
        self:checkDesktopGuide()
    end)

    self._connecterStateUI = cc.CSLoader:createNode(Res.ConnecterWeakUI)
    if self._connecterStateUI then
        self._connecterStateUI:setName("ConnecterStateUI")
        self.m_uiParent:addChild(self._connecterStateUI,SceneZOrder.connecterStateZOrder)
        self._connecterStateUI:setVisible(false)
        self._connecterStateUI:setPosition(display.cx,display.cy)
    end

    self.m_popupUi = PopupUI.new()
    self.m_popupUi:setName("PopupUIManager")
    self.m_uiParent:addChild(self.m_popupUi,SceneZOrder.popupUIZOrder)
    self.m_popupUi:setEmptyCB(function()
        --self:checkPayNotice()
        self:checkDesktopGuide()
        self:postDesktopState()
    end)

    self.m_systemMsgUi = PopupUI.new()
    self.m_systemMsgUi:setName("SystemMsgUIManager")
    self.m_uiParent:addChild(self.m_systemMsgUi,SceneZOrder.serverMessageZOrder)

    self.m_touchParticle = cc.ParticleSystemQuad:create(Res.touch2_plist)
    self.m_uiParent:addChild(self.m_touchParticle,SceneZOrder.touchParZOrder)
    self:resetTouchParticlePosition(0 - display.width * 2,0 - display.height * 2)

    -- init desktop
    self._desktopModel = DesktopModel.new()
    local DesktopController = app:getClass("DesktopController")
    self._desktopController = DesktopController.new(self._desktopModel)
    self._desktopController:setVisible(false)
    self.m_uiParent:addChild(self._desktopController,SceneZOrder.desktopZOrder)

    self._isInit = true
end

function UiHandler:playTouchParticle(posX,posY)
    self.m_touchParticle:setPosition(posX,posY)
    self.m_touchParticle:resetSystem()
end

function UiHandler:stopTouchParticle()
    self.m_touchParticle:stopSystem()
end

function UiHandler:setLastTouchPosition(posX,posY)
    self._lastTouchPositionX=posX
    self._lastTouchPositionY=posY
end

function UiHandler:setLastTouchPositionOffset(posX,posY)
    if self._lastTouchPositionX and self._lastTouchPositionY then
        self._lastTouchPositionX= self._lastTouchPositionX + posX
        self._lastTouchPositionY= self._lastTouchPositionY + posY
    end
end


function UiHandler:resetTouchParticlePosition(posX,posY)
    self.m_touchParticle:setPosition(posX,posY)
end

function UiHandler:reorderSystemUIToBattle()
    self.m_uiParent:reorderChild(self.m_systemUi,SceneZOrder.battleLayerZOrder + 1)
end

function UiHandler:reorderSystemUIToNormal()
    self.m_uiParent:reorderChild(self.m_systemUi,SceneZOrder.systemUIZOrder)
end

-- 是否有除Desktop之外的UI
function UiHandler:isHaveUI()
    -- print("system isHaveUI", self.m_systemUi:isHaveSystemUI())
    -- print("popup isHaveUI", self.m_popupUi:isHaveUI())
    -- print("story isHaveUI", self.m_storyModeUi:isHaveUI())
    -- print("is EnterStory", StoryManager:isEnterStoryMode())
    -- print("IM isHaveUI", app:sendMsg("IMRoomController", "isViewVisible"))

    -- 有系统界面，弹出界面，剧情界面时
    if self.m_systemUi:isHaveSystemUI() then return true end
    if self.m_popupUi:isHaveUI() then return true end
    if self.m_storyModeUi:isHaveUI() then return true end

    -- 剧情模式中，有StoryModeView
    if StoryManager:isEnterStoryMode() then return true end

    -- 聊天界面可见
    if app:sendMsg("IMRoomController", "isViewVisible") then return true end

    return false
end

-- isCompletely 完全删除，包括聊天界面／notDelete界面
function UiHandler:removeAllUI(isCompletely)
    self:hideFloatPanel()
    self.m_systemUi:removeAllUI()
    self.m_storyModeUi:removeAllUI()
    self.m_popupUi:removeAllUI()
    self:clearPopDialog()
    self:hideHeadMenu()

    if isCompletely then
        app:sendMsg("IMRoomController", "hideView")
        app:sendMsg("BoxController", "closeView")
        app:sendMsg("MallController", "closeView")
        app:sendMsg("CosplayController", "closeView")
    end

    -- 关闭Chess界面
    app:sendMsg("ChessController", "closeView")

    -- 清空已经存在的引导
    app:sendMsg("GuideController", "closeView")

    -- 清空道具获得动画
    app:sendMsg("UIController", "clearGetItemView")
end

-- 新功能开启界面时需要移除的ui
function UiHandler:removeUIForNewFeature()
    self:hideFloatPanel()
    self.m_systemUi:removeAllUI()
    app:sendMsg("IMRoomController", "hideView")

    -- 清空已经存在的引导
    app:sendMsg("GuideController", "closeView")
end

function UiHandler:hideIMBubble()
    local children = self.m_imBubbleUi:getChildren()
    for i,child in ipairs(children) do
        child:setVisible(false)
    end
end
function UiHandler:addIMBubble(render)
    self.m_imBubbleUi:addChild(render)
end

function UiHandler:addChildToUiParent(node, zOrder, name)
    if cc.isDead(node) or cc.isDead(self.m_uiParent) then return end
    if name then node:setName(name) end
    CCNode_addChild(self.m_uiParent, node, zOrder or 0)
end

function UiHandler:getChildFromUiParent(name)
    if cc.isDead(self.m_uiParent) then return end
    return CCNode_getChildByName(self.m_uiParent, name)
end

function UiHandler:removeChildFromUiParent(name)
    if cc.isDead(self.m_uiParent) then return end
    CCNode_removeChildByName(self.m_uiParent, name)
end

function UiHandler:addStoryUi(node,uiKey,notDelete)
    if cc.isDead(node) then return end
    print("===addStoryUi=========>>> ", node.__cname)
    self.m_storyModeUi:addUI(uiKey,node,notDelete)
end

function UiHandler:removeStoryUiByKey(uiKey)
    self.m_storyModeUi:removeUIByKey(uiKey)
end

function UiHandler:addPopupUi(popupUi,uiKey,notDelete)
    if cc.isDead(popupUi) then return end
    print("===addPopupUi=========>>> ", popupUi.__cname)
    self.m_popupUi:addUI(uiKey,popupUi,notDelete)
end

function UiHandler:removePopupUiByKey(uiKey)
    self.m_popupUi:removeUIByKey(uiKey)
end

function UiHandler:getPopupUiByKey(uiKey)
    return self.m_popupUi:getUIByKey(uiKey)
end

function UiHandler:addSystemUi(uiNode,uiKey,notDelete)
    -- print("===addSystemUi=========>>> ", uiNode.__cname)
    self.m_systemUi:addSystemUI(uiKey,uiNode,notDelete)
end

function UiHandler:removeSystemUiByKey(uiKey)
    self.m_systemUi:removeSystemUiByKey(uiKey)
end

function UiHandler:getSystemUiByKey(uiKey)
    return self.m_systemUi:getUIByKey(uiKey)
end

-- 上传处于主UI状态
function UiHandler:postDesktopState()
    if self:isHaveUI() then return end
    local actionState = FieldManager:getMyCharacterActionState()
    app:sendMsg("TeamModel", "reqPostPlayerState", actionState)
end

---
-- msg table 自行扩展所需传入参数到msg中
-- 打开 ui msg = {id = funcId,mode = "open"}
-- 关闭 ui msg = {id = funcId,mode = "close"}
--
function UiHandler:handleMessage(msg)
	local functionId = msg.id
	local mode = msg.mode
    if mode == "open" and not self:isFunctionOpen(functionId) then
        if functionId ~= Constant.FUNC_TYPE_BATTLE_FAILED then
            if functionId == Constant.FUNC_TYPE_REWARD_TRACE3 then
                display.pushToast( L("tips_1110010") ) --首充的来源跳转特殊处理
                return
            end
            display.showFunctionNotOpenDetail(functionId)
        end
        return
    end
    
    if mode == "open" then
        app:sendMsg("TeamModel", "reqPostPlayerState", functionId)
    end

    if functionId == Constant.FUNC_TYPE_BIGMAP then--大地图
        -- 废弃
    elseif functionId == Constant.FUNC_TYPE_TASK then--任务
        if mode == "open" then
            app:sendMsg("TaskController", "openView")
        elseif mode == "close" then
            app:sendMsg("TaskController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_TASK_ROADHERO then--任务-英雄之路
        if mode == "open" then
            app:sendMsg("TaskController", "openView", {Constant.FUNC_TYPE_TASK_ROADHERO})
        elseif mode == "close" then
            app:sendMsg("TaskController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_TASK_BRANCH then--任务
        if mode == "open" then
            app:sendMsg("TaskController", "openView", {Constant.FUNC_TYPE_TASK_BRANCH})
        elseif mode == "close" then
            app:sendMsg("TaskController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_TASK_DAILY then--每日任务
        if mode == "open" then
            app:sendMsg("TaskController", "openView", {Constant.FUNC_TYPE_TASK_DAILY})
        elseif mode == "close" then
            app:sendMsg("TaskController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_TASK_GOLD then-- 赏金任务
        if mode == "open" then
            app:sendMsg("TaskController", "openView", {Constant.FUNC_TYPE_TASK_GOLD})
        elseif mode == "close" then
            app:sendMsg("TaskController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_MINIMAP then-- 展开地图
        if mode == "open" then
            app:sendMsg("WorldMapController", "openView" )
        elseif mode == "close" then
            app:sendMsg("WorldMapController", "closeView" )
        end
    elseif functionId == Constant.FUNC_TYPE_BATTLEMAP then-- 展开地图
        if mode == "open" then
            app:sendMsg("WorldBattleController", "openView" )
        elseif mode == "close" then
            app:sendMsg("WorldBattleController", "closeView" )
        end
    elseif functionId == Constant.FUNC_TYPE_CJ
        or functionId == Constant.FUNC_TYPE_MEDAL then--成就、勋章
        if mode == "open" then
            if not msg.labelType then
                if functionId == Constant.FUNC_TYPE_CJ then
                    msg.labelType = 1
                elseif functionId == Constant.FUNC_TYPE_MEDAL then
                    msg.labelType = 1
                end
            end
            self:showAchievementUI(msg.achType,msg.labelType)
        elseif mode == "close" then
            self.m_systemUi:removeSystemUiByKey("m_achController")
        end
    elseif functionId == Constant.FUNC_TYPE_CAPTAIN_ROOM then -- 打开船长室
        if mode == "open" then
            app:sendMsg("CaptainController", "openCaptainView", UD.uid)
        elseif mode == "close" then
            app:sendMsg("CaptainController", "closeCaptainView" )
        end
    elseif functionId == Constant.FUNC_TYPE_OTHER_CAPTAIN_ROOM then -- 打开其他玩家的船长室
        if mode == "open" then
            app:sendMsg("CaptainController", "openRandCaptainView")
        elseif mode == "close" then
            app:sendMsg("CaptainController", "closeCaptainView" )
        end
    elseif functionId == Constant.FUNC_TYPE_DUNGEONS then -- 地下城查找器
        if mode == "open" then
            app:sendMsg("NewDungeonTypeController", "openView" )
        elseif mode == "close" then
            app:sendMsg("NewDungeonTypeController", "closeView" )
        end
    elseif functionId == Constant.FUNC_TYPE_PVP then -- pvp 锦标赛
        if mode == "open" then
            app:sendMsg("PvpController", "openView" )
        elseif mode == "close" then
            app:sendMsg("PvpController", "closeView" )
        end
    elseif functionId == Constant.FUNC_TYPE_CHAMPION then
        if mode == "open" then
            app:sendMsg("PvpController", "openView", 2)
        elseif mode == "close" then
            app:sendMsg("PvpController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_CHALLENGE then -- 挑战赛
        if mode == "open" then
            app:sendMsg("PvpChallengeController", "openView")
        elseif mode == "close" then
            app:sendMsg("PvpChallengeController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_DUEL then -- 决斗赛
        if mode == "open" then
            app:sendMsg("PvpController", "openView", 3)
        elseif mode == "close" then
            app:sendMsg("PvpController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_DAILY_TASK then
        if mode == "open" then
            app:sendMsg("DailyController", "openView")
        elseif mode == "close" then
            app:sendMsg("DailyController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_DAILY then
        if mode == "open" then
            app:sendMsg("DailyController", "openView")
        elseif mode == "close" then
            app:sendMsg("DailyController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_DAILY_WISH_WORLD then
        if mode == "open" then
            app:sendMsg("DailyController", "openView", 3)
        elseif mode == "close" then
            app:sendMsg("DailyController", "close")
        end
    elseif functionId == Constant.FUNC_TYPE_DAILY_RARE then -- 日常-宝物
        if mode == "open" then
            app:sendMsg("DailyController", "openView", 2)
        elseif mode == "close" then
            app:sendMsg("DailyController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_ACTIVITY_DUNGEONS then -- 活动副本入口
        if mode == "open" then
            app:sendMsg("NewActivityDungeonsController", "openView" )
        elseif mode == "close" then
            app:sendMsg("NewActivityDungeonsController", "closeView" )
        end
    elseif functionId == Constant.FUNC_TYPE_CREATE_TEAM then -- 创建队伍
        if mode == "open" then
            if app:sendMsg("TeamModel", "hasTeam") then
                app:sendMsg("NewTeamMemberController", "openView")
            else
                local creataeTeamDialog = display.newConfirmDialog( L("lua_code_text_190"),
                    function() -- 确定
                        app:sendMsg("TeamModel", "reqCreateTeam")
                    end)
                UIHandler:addPopDialog( creataeTeamDialog )
            end
        elseif mode == "close" then
            app:sendMsg("NewTeamMemberController", "closeView" )
        end
    elseif functionId == Constant.FUNC_TYPE_TEAMMATCHING then -- 组队查找器
        if mode == "open" then
            app:sendMsg("TeamMatchController", "openView", msg.data )
        elseif mode == "close" then
            app:sendMsg("TeamMatchController", "closeView" )
        end
    elseif functionId == Constant.FUNC_TYPE_TEAMMATCHING_TEAM then -- 组队查找器 - 小队
        if mode == "open" then
            local params = (msg.targetId ~= nil) and msg or {matchType=Enums.TeamMatchType.Dungeon, targetType=Enums.TeamTargetType.normal}
            app:sendMsg("TeamMatchController", "openView", params)
        elseif mode == "close" then
            app:sendMsg("TeamMatchController", "closeView" )
        end
    elseif functionId == Constant.FUNC_TYPE_TEAMMATCHING_SPEED then -- 组队查找器 - 竞速
        if mode == "open" then
            local params = (msg.targetId ~= nil) and msg or {matchType=Enums.TeamMatchType.Dungeon, targetType=Enums.TeamTargetType.speed}
            app:sendMsg("TeamMatchController", "openView", params)
        elseif mode == "close" then
            app:sendMsg("TeamMatchController", "closeView" )
        end
    elseif functionId == Constant.FUNC_TYPE_TEAMMATCHING_LEGION then -- 组队查找器 - 团本
        if mode == "open" then
            local params = (msg.targetId ~= nil) and msg or {matchType=Enums.TeamMatchType.Dungeon, targetType=Enums.TeamTargetType.legion}
            app:sendMsg("TeamMatchController", "openView", params)
        elseif mode == "close" then
            app:sendMsg("TeamMatchController", "closeView" )
        end
    elseif functionId == Constant.FUNC_TYPE_TEAMMATCHING_SECRET then -- 组队查找器 - 秘境
        if mode == "open" then
            local params = (msg.targetId ~= nil) and msg or {matchType=Enums.TeamMatchType.Dungeon, targetType=Enums.TeamTargetType.secret}
            app:sendMsg("TeamMatchController", "openView", params)
        elseif mode == "close" then
            app:sendMsg("TeamMatchController", "closeView" )
        end
    elseif functionId == Constant.FUNC_TYPE_TEAMMATCHING_PVP then -- 组队查找器 - 竞技场
        if mode == "open" then
            local params = {targetId=Enums.TeamTarget.arena}
            app:sendMsg("TeamMatchController", "openView", params)
        elseif mode == "close" then
            app:sendMsg("TeamMatchController", "closeView" )
        end
    elseif functionId == Constant.FUNC_TYPE_TEAMMATCHING_FIGHTS then -- 组队查找器 - 赤道大乱斗
        if mode == "open" then
            local params = {targetId=Enums.TeamTarget.melee}
            app:sendMsg("TeamMatchController", "openView", params)
        elseif mode == "close" then
            app:sendMsg("TeamMatchController", "closeView" )
        end
    elseif functionId == Constant.FUNC_TYPE_TEAMMATCHING_THEATRE then -- 组队查找器 - 奇迹歌剧院
        if mode == "open" then
            local params = {targetId=Enums.TeamTarget.theatre}
            app:sendMsg("TeamMatchController", "openView", params)
        elseif mode == "close" then
            app:sendMsg("TeamMatchController", "closeView" )
        end
    elseif functionId == Constant.FUNC_TYPE_TEAMMATCHING_ACTIVITY then -- 组队查找器 - 活动副本
        if mode == "open" then
            local params = {matchType=Enums.TeamMatchType.Activity}
            app:sendMsg("TeamMatchController", "openView", params)
        elseif mode == "close" then
            app:sendMsg("TeamMatchController", "closeView" )
        end
    elseif functionId == Constant.FUNC_TYPE_ACTIVITY_DUNGEONS_LIONHEART then -- 组队查找器 - 活动-狮心号角
        if mode == "open" then
            local params = {targetId=Enums.TeamTarget.lionHeart}
            app:sendMsg("TeamMatchController", "openView", params)
        elseif mode == "close" then
            app:sendMsg("TeamMatchController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_ACTIVITY_DUNGEONS_FISHVSZOMBIE then -- 组队查找器 - 活动-鱼人大战僵尸
        if mode == "open" then
            local params = {targetId=Enums.TeamTarget.fishVSZombie}
            app:sendMsg("TeamMatchController", "openView", params)
        elseif mode == "close" then
            app:sendMsg("TeamMatchController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_ACTIVITY_DUNGEONS_KOF then -- 组队查找器 - 活动-决斗之王
        if mode == "open" then
            local params = {targetId=Enums.TeamTarget.kof}
            app:sendMsg("TeamMatchController", "openView", params)
        elseif mode == "close" then
            app:sendMsg("TeamMatchController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_ACTIVITY_DUNGEONS_ASHINVADE then -- 组队查找器 - 活动-灰烬入侵
        if mode == "open" then
            local params = {targetId=Enums.TeamTarget.ashInvade}
            app:sendMsg("TeamMatchController", "openView", params)
        elseif mode == "close" then
            app:sendMsg("TeamMatchController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_ACTIVITY_DUNGEONS_TRAINING then     -- 组队查找器 训练场
        if mode == "open" then
            local params = {targetId=Enums.TeamTarget.training}
            app:sendMsg("TeamMatchController", "openView", params)
        elseif mode == "close" then
            app:sendMsg("TeamMatchController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_TEAMMATCHING_CHESS then -- 组队查找器 - 星空谜棋
        if mode == "open" then
            local params = {targetId=Enums.TeamTarget.chess}
            app:sendMsg("TeamMatchController", "openView", params)
        elseif mode == "close" then
            app:sendMsg("TeamMatchController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_POOR_EXP then -- 世界锁
        if mode == "open" then
            app:sendMsg("PlayerController", "showWorldExpLockView")
        end
    elseif functionId == Constant.FUNC_TYPE_PACK then--角色背包
        if mode == "open" then
            app:sendMsg("NewBagController", "openView")
        elseif mode == "close" then
            app:sendMsg("NewBagController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_PACK_TREASURE then--角色宝物
        if mode == "open" then
            app:sendMsg("NewBagController", "openView", { idx = 2 })
        elseif mode == "close" then
            app:sendMsg("NewBagController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_PACK_PRESTIGE then--角色声望
        if mode == "open" then
            app:sendMsg("NewBagController", "openView", { idx = 5 })
        elseif mode == "close" then
            app:sendMsg("NewBagController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_CORE_PROP then -- 核心属性
        if mode == "open" then
            app:sendMsg("CorePropController", "openView")
        elseif mode == "close" then
            app:sendMsg("CorePropController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_SKILL then--技能
        if mode == "open" then
            app:sendMsg("SkillController", "openView")
        elseif mode == "close" then
            app:sendMsg("SkillController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_SKILL_TALENT then -- 天赋
        if mode == "open" then
            app:sendMsg("SkillController", "openView", 2)
        elseif mode == "close" then
            app:sendMsg("SkillController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_SKILL_RUNE then -- 符文
        if mode == "open" then
            app:sendMsg("SkillController", "openView", 3)
        elseif mode == "close" then
            app:sendMsg("SkillController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_LEGEND or
        functionId == Constant.FUNC_TYPE_LEGEND_STARMAP or
        functionId == Constant.FUNC_TYPE_LEGEND_FASHION then -- 神器
        if mode == "open" then
            app:sendMsg("LegendController", "openView", functionId)
        elseif mode == "close" then
            app:sendMsg("LegendController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_AVATAR_SHOP then -- 招募 组队查找器
        if mode == "open" then
            app:sendMsg("AvatarShopController", "openView")
        elseif mode == "close" then
            app:sendMsg("AvatarShopController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_RECRUIT then -- 招募 组队查找器
        display.pushToast( L("lua_code_text_138") )
    elseif functionId == Constant.FUNC_TYPE_MOUNT then--坐骑
        if mode == "open" then
            app:sendMsg("MountController", "openView")
        elseif mode == "close" then
            app:sendMsg("MountController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_MOUNT_PIT then -- 兽栏
        if mode == "open" then
            app:sendMsg("MountController", "openView", 2)
        elseif mode == "close" then
            app:sendMsg("MountController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_PET then--宠物
    elseif functionId == Constant.FUNC_TYPE_AUCTION_SHOP then
        if mode == "open" then
            if msg.tabIdx then
                app:sendMsg("AuctionController", "openView", {tabIdx = msg.tabIdx, auctionType = msg.auctionType, searchName = msg.searchName})
            elseif msg.tipsData then
                app:sendMsg("AuctionController", "openView", {tipsData = msg.tipsData})
            else
                app:sendMsg("AuctionController", "openView")
            end
        elseif mode == "close" then
            app:sendMsg("AuctionController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_BLESS then
        if mode == "open" then
            app:sendMsg("WorldBlessController", "openView")
        elseif mode == "close" then
            app:sendMsg("WorldBlessController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_BANK then
        -- 银行暂时废弃
    elseif functionId == Constant.FUNC_TYPE_GANG then--公会
        if mode == "open" then
            if UD:isInGuild() then -- 有工会？
                if msg.tabIdx then
                    app:sendMsg("NewguildController", "openView", {tabIdx = msg.tabIdx, itemType = msg.itemType, itemId = msg.itemId})
                else
                    app:sendMsg("NewguildController", "openView")
                end
            else
                app:sendMsg("NewguildPreController", "openView")
            end
        elseif mode == "close" then
            if UD:isInGuild() then -- 有工会？
                app:sendMsg("NewguildController", "closeView")
            else
                app:sendMsg("NewguildPreController", "closeView")
            end
        end
    elseif functionId == Constant.FUNC_TYPE_JEWEL then -- 宝石镶嵌
        if mode == "open" then
            app:sendMsg("JewelController", "openView",{menuIndex = msg.menuIndex or 1,equipUid = msg.equipUid ,jewelUid = msg.jewelUid})
         elseif mode == "close" then
            app:sendMsg("JewelController", "closeView")
         end
     elseif functionId == Constant.FUNC_TYPE_JEWEL_STRENGTH then -- 宝石升级
         if mode == "open" then
            app:sendMsg("JewelController", "openView",{menuIndex = 2})
         elseif mode == "close" then
            app:sendMsg("JewelController", "closeView")
        end
     elseif functionId == Constant.FUNC_TYPE_JEWEL_TRANSFORM then -- 宝石转换
         if mode == "open" then
            app:sendMsg("JewelController", "openView",{menuIndex = 3})
         elseif mode == "close" then
            app:sendMsg("JewelController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_TIPS_CRYSTAL_LVUP then -- 水晶强化
         if mode == "open" then
            app:sendMsg("CrystalController", "openStrengthView", msg.data)
         elseif mode == "close" then
            app:sendMsg("CrystalController", "closeStrengthView")
         end
    elseif functionId == Constant.FUNC_TYPE_TIPS_CRYSTAL_INLAY then -- 水晶镶嵌
        if mode == "open" then
            --判断msg.equipUid 是否存在 若不存在 取人身上的背部装备 若有 则用 若无 则提示
            if msg.equipUid then
                app:sendMsg("CrystalController", "openInlayView", msg.equipUid)
            else
                local equip = UD:getEquipByPos(6)
                if equip then 
                    app:sendMsg("CrystalController", "openInlayView", equip:getUid())
                else
                    display.pushToast(L("ErrNoEquip"))
                end
            end
        elseif mode == "close" then
            app:sendMsg("CrystalController", "closeInlayView")
        end
    elseif functionId == Constant.FUNC_TYPE_WELFARE then--福利
        if mode == "open" then
            app:sendMsg("RewardController", "openView")
        elseif mode == "close" then
            app:sendMsg("RewardController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_ONLINE_REWARD then--福利-在线定时领奖
        if mode == "open" then
            app:sendMsg("RewardController", "openView", 9)
        elseif mode == "close" then
            app:sendMsg("RewardController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_MAIL then--邮件
        if mode == "open" then
            app:sendMsg("MailController", "openView")
        elseif mode == "close" then
           app:sendMsg("MailController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_FRIEND then--好友
        if mode == "open" then
            app:sendMsg("FriendController", "openView")
        elseif mode == "close" then
            app:sendMsg("FriendController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_SHOP then --商城
        if mode == "open" then
            app:sendMsg("MallController", "openView", {tabKey=msg.tabKey, shopIndex=msg.shopIndex, itemType=msg.itemType, itemId=msg.itemId})
        elseif mode == "close" then
            app:sendMsg("MallController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_SHOPDRAW then -- 奇迹卡片
        if mode == "open" then
            app:sendMsg("MallController", "openView", {tabKey=Constant.FUNC_TYPE_SHOPDRAW, shopIndex = msg.shopIndex})
        elseif mode == "close" then
            app:sendMsg("MallController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_LOTTERY then -- 抽奖
        if mode == "open" then
            app:sendMsg("MallController", "openView", {tabKey=Constant.FUNC_TYPE_LOTTERY})
        elseif mode == "close" then
            app:sendMsg("MallController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_RECHARGE then -- 充值
        if mode == "open" then
            app:sendMsg("MallController", "openView", {tabKey=Constant.FUNC_TYPE_RECHARGE})
        elseif mode == "close" then
            app:sendMsg("MallController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_EMA_SERVER_GIFT then -- 开服礼包
        if mode == "open" then
            app:sendMsg("MallController", "openView", {tabKey=Constant.FUNC_TYPE_EMA_SERVER_GIFT})
        elseif mode == "close" then
            app:sendMsg("MallController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_PRESTIGE_DONATE then--声望捐献
    elseif functionId == Constant.FUNC_TYPE_IDENTIFICATION then--鉴定
    elseif functionId == Constant.FUNC_TYPE_SPLENDOR_HISTORY then --光辉历史
        if mode == "open" then
            self:showHistoryUI()
        elseif mode == "close" then
            self.m_systemUi:removeSystemUiByKey("m_historyController")
        end
    elseif functionId == Constant.FUNC_TYPE_COMPOUND then--合成
        if mode == "open" then
            if msg.lifeId and msg.levelId and msg.formulaId then
                if UD:getLifeSkillById(msg.lifeId) == nil then
                    display.pushToast(L("ErrLifeSkillNotStudy"))
                    return
                end
                app:sendMsg("MakeController", "open", {lifeId = msg.lifeId, levelId = msg.levelId, formulaId = msg.formulaId})
            else
                self:dispatchEvent({name = "onOpenMake"})
            end
        elseif mode == "close" then
            self:dispatchEvent({name = "onCloseMake"})
        end
    elseif functionId == Constant.FUNC_TYPE_WEEKTASK then --每周任务
    elseif functionId == Constant.FUNC_TYPE_ACTIVITY then --活动
        if mode == "open" then
            if msg.subKey then
                app:sendMsg("HandbookController", "openView", msg.subKey)
            else
                app:sendMsg("HandbookController", "openView")
            end
        elseif mode == "close" then
            app:sendMsg("HandbookController", "closeView")
        end
    elseif functionId == Constant.FUNC_DAILY_WORKFLOW then
        if mode == "open" then
            app:sendMsg("DailyworkflowController", "openView", msg.data)
        elseif mode == "close" then
            app:sendMsg("DailyworkflowController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_PREVIEW then -- 玩法预告
        if mode == "open" then
            app:sendMsg("GameplaypreviewController", "openView")
        elseif mode == "close" then
            app:sendMsg("GameplaypreviewController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_BATTLE_FAILED then
        if mode == "open" then
            self:battleFailedUIVisibility(true)
        elseif mode == "close" then
           self:battleFailedUIVisibility(false)
        end
    elseif functionId == Constant.FUNC_TYPE_CALENDAR
        or functionId == Constant.FUNC_TYPE_DAILYTASK
        or functionId == Constant.FUNC_TYPE_CALENDAR_CIRCLE_LABEL
        or functionId == Constant.FUNC_TYPE_WEEK_CALENDAR then
    elseif functionId == Constant.FUNC_TYPE_SET then
       if mode == "open" then
            app:sendMsg("SettingController", "openView", msg.data)
        elseif mode == "close" then
            app:sendMsg("SettingController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_ROLE then
        -- 主角信息，已经废弃
    elseif functionId == Constant.FUNC_TYPE_TRANSFER then
        if mode == "open" then
            self:transferUiVisibility(true,msg.call)
        elseif mode == "close" then
            self:transferUiVisibility(false)
        end
    elseif functionId == Constant.FUNC_TYPE_RENAME then
        if mode == "open" then

        elseif mode == "close" then

        end
    elseif functionId == Constant.FUNC_TYPE_MERCENARY then
        if mode == "open" then
            self:mecenaryUiVisibility(true,msg.story,msg.returnCallback,msg.partnerId)
        elseif mode == "close" then
            self:mecenaryUiVisibility(false)
        end
    elseif functionId == Constant.FUNC_TYPE_PHOTOGRAPH then
        if mode == "open" then
            self:showPhotoUI()
        elseif mode == "close" then
            self:hidePhotoUI()
        end
    elseif functionId == Constant.FUNC_TYPE_BOSS_SHARE then
        if mode == "open" then
            app:sendMsg("ShareController", "shareBoss")
        elseif mode == "close" then

        end
    elseif functionId == Constant.FUNC_TYPE_MOUNT_SHARE then
        if mode == "open" then
            app:sendMsg("ShareController", "shareMount")
        elseif mode == "close" then

        end
    elseif functionId == Constant.FUNC_TYPE_STRONGER then
        -- 已废弃
        if mode == "open" then

        elseif mode == "close" then

        end
    elseif functionId == Constant.FUNC_TEAM_MATCH_DIALOG then
    elseif functionId == Constant.FUNC_TYPE_TEAMGROUP then
        if mode == "open" then
            app:sendMsg("TeamLegionController", "openView")
        elseif mode == "close" then
            app:sendMsg("TeamLegionController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_ARENA_VS then
        if mode == "open" then
            self:showArenaVs(msg.data)
        elseif mode == "close" then
            self:hideArenaVs()
        end
    elseif functionId == Constant.FUNC_TYPE_RANK then
        if checknumber(msg.rankingId) >= Enums.GuildRankType.GuildLv and checknumber(msg.rankingId) <= Enums.GuildRankType.CSTotalProsperity then
            if mode == "open" then
                app:sendMsg("NewRankController", "openView", checknumber(msg.rankingId))
            elseif mode == "close" then
                app:sendMsg("NewRankController", "closeView")
            end
        else
            if mode == "open" then
                self:showRankingUI(msg.rankingId)
            elseif mode == "close" then
                self.m_systemUi:removeSystemUiByKey("m_rankingController")
            end
        end
    elseif functionId == Constant.FUNC_TYPE_ACHIEVEMENT then
        if mode == "open" then
            self:showAchievementUI(msg.achType,msg.labelType)
        elseif mode == "close" then
            self.m_systemUi:removeSystemUiByKey("m_achController")
        end
    elseif functionId == Constant.FUNC_SHOP_ACHIEVEMENT then -- 成就商店
        if mode == "open" then
            self:showAchievementUI( nil, AchievementManager.tabShop, msg.itemType, msg.itemId )
        elseif mode == "close" then
            self.m_systemUi:removeSystemUiByKey("m_achController")
        end
    elseif functionId == Constant.FUNC_SHOP_FAME_1 or
            functionId == Constant.FUNC_SHOP_FAME_2 or
            functionId == Constant.FUNC_SHOP_FAME_3 then
                -- FUNC_SHOP_FAME_1 = 10601, -- 石剑村声望商店 对应 shopId = 72011
                local function transFuncIdToShopId( functionId )
                    return 72011 + ( functionId - Constant.FUNC_SHOP_FAME_1 )
                end
                if mode == "open" then
                    app:sendMsg("PrestigeShopController", "openView", { shopId = transFuncIdToShopId( functionId ), itemType = msg.itemType, itemId = msg.itemId })
                elseif mode == "close" then
                    app:sendMsg("PrestigeShopController", "closeView")
                end
    elseif functionId == Constant.FUNC_SHOP_FAME_4 or
            functionId == Constant.FUNC_SHOP_FAME_5 or
            functionId == Constant.FUNC_SHOP_FAME_6 then
                -- FUNC_SHOP_FAME_4 = 10604, -- 夜火村声望商店 对应 shopId = 72021
                local function transFuncIdToShopId( functionId )
                    return 72021 + ( functionId - Constant.FUNC_SHOP_FAME_4 )
                end
                if mode == "open" then
                    app:sendMsg("PrestigeShopController", "openView", { shopId = transFuncIdToShopId( functionId ), itemType = msg.itemType, itemId = msg.itemId })
                elseif mode == "close" then
                    app:sendMsg("PrestigeShopController", "closeView")
                end

    elseif functionId == Constant.FUNC_SHOP_FAME_7 or
            functionId == Constant.FUNC_SHOP_FAME_8 or
            functionId == Constant.FUNC_SHOP_FAME_9 then
                -- FUNC_SHOP_FAME_7 = 10607, -- 工匠镇声望商店 对应 shopId = 72031
                local function transFuncIdToShopId( functionId )
                    return 72031 + ( functionId - Constant.FUNC_SHOP_FAME_7 )
                end
                if mode == "open" then
                    app:sendMsg("PrestigeShopController", "openView", { shopId = transFuncIdToShopId( functionId ), itemType = msg.itemType, itemId = msg.itemId })
                elseif mode == "close" then
                     app:sendMsg("PrestigeShopController", "closeView")
                end
    elseif functionId == Constant.FUNC_SHOP_FAME_10 or
            functionId == Constant.FUNC_SHOP_FAME_11 or
            functionId == Constant.FUNC_SHOP_FAME_12 then
                -- FUNC_SHOP_FAME_10 = 10610, -- 黑金镇声望商店 对应 shopId = 72041
                local function transFuncIdToShopId( functionId )
                    return 72041 + ( functionId - Constant.FUNC_SHOP_FAME_10 )
                end
                if mode == "open" then
                    app:sendMsg("PrestigeShopController", "openView", { shopId = transFuncIdToShopId( functionId ), itemType = msg.itemType, itemId = msg.itemId })
                elseif mode == "close" then
                     app:sendMsg("PrestigeShopController", "closeView")
                end
                
    elseif functionId == Constant.FUNC_SHOP_FAME_99 then
                print("Open FUNC_SHOP_FAME_WORLD")
                if mode == "open" then
                    app:sendMsg("PrestigeShopController", "openView", { shopId = 72000, itemType = msg.itemType, itemId = msg.itemId })
                elseif mode == "close" then
                     app:sendMsg("PrestigeShopController", "closeView")
                end
    elseif functionId == Constant.FUNC_SHOP_HEROMEDAL then
                print("Open FUNC_SHOP_HEROMEDAL")
                if mode == "open" then
                    app:sendMsg("PrestigeShopController", "openView", { shopId = 72061, itemType = msg.itemType, itemId = msg.itemId })
                elseif mode == "close" then
                     app:sendMsg("PrestigeShopController", "closeView")
                end

    elseif functionId == Constant.FUNC_SHOP_BRIGHTMEDAL then
                print("Open FUNC_SHOP_BRIGHTMEDAL")
                if mode == "open" then
                    app:sendMsg("PrestigeShopController", "openView", { shopId = 72062, itemType = msg.itemType, itemId = msg.itemId })
                elseif mode == "close" then
                     app:sendMsg("PrestigeShopController", "closeView")
                end
    elseif functionId == Constant.FUNC_SHOP_ALLMEDAL then
        print("Open FUNC_SHOP_ALLMEDAL")
        if mode == "open" then
            app:sendMsg("PrestigeShopController", "openView", { shopId = 72063, itemType = msg.itemType, itemId = msg.itemId })
        elseif mode == "close" then
            app:sendMsg("PrestigeShopController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_REWARD_TRACE1
        or functionId == Constant.FUNC_TYPE_REWARD_TRACE2
        or functionId == Constant.FUNC_TYPE_REWARD_TRACE3
        or functionId == Constant.FUNC_TYPE_REWARD_TRACE4 then
        if mode == "open" then
            local rewardModel = app:getInst("RewardModel")
            local idx = 1
            if functionId == Constant.FUNC_TYPE_REWARD_TRACE1 then
                idx = 1
            elseif functionId == Constant.FUNC_TYPE_REWARD_TRACE2 then
                idx = 2
            elseif functionId == Constant.FUNC_TYPE_REWARD_TRACE3 then
                idx = 3
            elseif functionId == Constant.FUNC_TYPE_REWARD_TRACE4 then
                idx = 4
            end

            app:sendMsg("RewardController", "openView", rewardModel:getTraceDataByIdx(idx))
        elseif mode == "close" then
            app:sendMsg("RewardController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_REWARD_TRACE then
        if mode == "open" then
            local rewardModel = app:getInst("RewardModel")
            app:sendMsg("RewardController", "openView", rewardModel:getFirstWeflareActivity())
        elseif mode == "close" then
            app:sendMsg("RewardController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_REWARD_MONITOR_TRACE then
        if mode == "open" then
            local rewardModel = app:getInst("RewardModel")
            app:sendMsg("RewardController", "openMonitorView")
        elseif mode == "close" then
            app:sendMsg("RewardController", "closeMonitorView")
        end
    elseif functionId == Constant.FUNC_TYPE_REWARD_DRAW then
        if mode == "open" then
            local rewardModel = app:getInst("RewardModel")
            app:sendMsg("RewardController", "openView", rewardModel:getDrawActivity())
        elseif mode == "close" then
            app:sendMsg("RewardController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_DYNASTY_BATTLE then
        if mode == "open" then
            app:sendMsg("DynastyBattleController", "openView", {msg.subData})
        elseif mode == "close" then
            app:sendMsg("DynastyBattleController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_WORLD_BOSS then
        if mode == "open" then
            app:sendMsg("WorldBossController", "openView", 2)
        elseif mode == "close" then
            app:sendMsg("WorldBossController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_MSDK_QQ then
        UD.msdkData:qqGameWakeUpClick()
    elseif functionId == Constant.FUNC_TYPE_MSDK_QQ_VIP then
        UD.msdkData:qqVipClick()
    elseif functionId == Constant.FUNC_TYPE_MSDK_WX then
        UD.msdkData:wxGameWakeUpClick()
    elseif functionId == Constant.FUNC_TYPE_SKILL_CHANGE then
        if mode == "open" then
            app:sendMsg("SkillChangeController", "openView")
        elseif mode == "close" then
            app:sendMsg("SkillChangeController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_OVERSEA_ACCOUNT_UYPGRADE then
        app.channelAPI:openGuestUpgrade()
    elseif functionId == Constant.FUNC_TYPE_OVERSEA_CUSTOMER_SERVICE then
        app.channelAPI:openSupport()
    elseif functionId == Constant.FUNC_TYPE_CS_GUILD_WAR then
        if mode == "open" then
            app:sendMsg("CrossServerController", "openView", Enums.CrossServerTab.GuildWar, msg.secondTabIndex, msg.other)
        elseif mode == "close" then
            app:sendMsg("CrossServerController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_CS_ELITEMATCH then
        if mode == "open" then
            app:sendMsg("PvpController", "openView", 1, msg.secondTabIndex)
        elseif mode == "close" then
            app:sendMsg("PvpController", "closeView" )
        end
    elseif functionId == Constant.FUNC_TYPE_CS_SHOP then
        -- if mode == "open" then
        --     app:sendMsg("CrossServerController", "openView", {type = Enums.CrossServerTab.Shop, shopId = 72072, itemType = msg.itemType, itemId = msg.itemId })
        -- elseif mode == "close" then
        --     app:sendMsg("CrossServerController", "closeView")
        -- end
    elseif functionId == Constant.FUNC_TYPE_CROSSSERVER then
        if mode == "open" then
            app:sendMsg("CrossServerController", "openView")
        elseif mode == "close" then
            app:sendMsg("CrossServerController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_SUPER_RANK then
        if mode == "open" then
            app:sendMsg("SuperRankController", "openView", msg.menuType)
        elseif mode == "close" then
            app:sendMsg("CrossServerController", "closeView")
        end

    elseif functionId == Constant.FUNC_TYPE_GUIDE_STRENGTHEN then
        --我要变强
        if mode == "open" then
            app:sendMsg("HandbookController", "openView", Constant.DirectoryChallengeConst)
        elseif mode == "close" then
            app:sendMsg("HandbookController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_RECAST_STENGTHEN then
        --打开强化界面
        if mode == "open" then
            app:sendMsg("NewBagController", "openView",{showQuickStrength = true})
        elseif mode == "close" then
            app:sendMsg("NewBagController", "closeView")
        end
    elseif functionId == Constant.FUNC_TYPE_HERO_ROAD then
        --打开英雄之路界面
        if mode == "open" then
            app:sendMsg("TaskController", "openView", {Constant.FUNC_TYPE_TASK_ROADHERO})
        elseif mode == "close" then
            app:sendMsg("TaskController", "closeView")
        end
    end

    EM:notify("OnFunctionUIChanged",functionId,mode)
end

function UiHandler:showAchievementUI(achType,labelType, itemType, itemId)
    local achController = self.m_systemUi:getUIByKey("m_achController")
    if not achController then
        local AchievementController = app:getClass("AchievementController")
        achController = AchievementController.new(achType,labelType)
        self.m_systemUi:addSystemUI("m_achController", achController)
    else
        achController:setVisible(true)
    end

    -- labelType = 2
    AchievementManager:reqAchievements()
    achController:selectTab(labelType, itemType, itemId)
end

function UiHandler:showHistoryUI()
    local hController = self.m_systemUi:getUIByKey("m_historyController")
    if not hController then
        local HistoryController = app:getClass("HistoryController")
        self.m_systemUi:addSystemUI("m_historyController",HistoryController.new())
    else
        hController:setVisible(true)
    end
end

function UiHandler:showRankingUI(aRankingId)
    -- aRankingId = 90000
    local hController = self.m_systemUi:getUIByKey("m_rankingController")
    if not hController then
        local RankingController = app:getClass("RankingController")
        self.m_systemUi:addSystemUI("m_rankingController",RankingController.new(aRankingId))
    else
        hController:setVisible(true)
    end
end

function UiHandler:showPhotoUI()
    app:getInst("PhotoController"):showPhotoView()
end

function UiHandler:hidePhotoUI()
    self.m_systemUi:removeSystemUiByKey("m_photoController")
end

-- 战斗失败界面
function UiHandler:battleFailedUIVisibility(visible)
    if visible then
        local battleFailedView = self.m_popupUi:getUIByKey("BattleFailedView")
        if not battleFailedView then
            battleFailedView = app:getClass("BattleFailedView").new()
            self.m_popupUi:addUI("BattleFailedView", battleFailedView)
            battleFailedView:onCloseView(function(sender)
                self:removePopupUiByKey("BattleFailedView")
            end)
        end
        battleFailedView:show()
    else
        local battleFailedView = self.m_popupUi:getUIByKey("BattleFailedView")
        if battleFailedView then
            battleFailedView:closeView()
        end
    end
end

-- 传送界面
function UiHandler:transferUiVisibility(visible,overCall)
    MapManager:backCameraOffsetToOriginal(0.1,function()
        if visible then
            local transferView = self.m_popupUi:isCreateUi( "m_transferView" )
            if not transferView then
                local Transfer = app:getClass("Transfer")
                transferView = Transfer.new(overCall)
                self.m_popupUi:addUI( "m_transferView",transferView,true )
            else
                transferView:setVisible(true)
            end
            transferView:setStopCallback(function()
                FieldManager:breakTransfer()
                FieldManager:characterForceStandby()
            end)

            transferView:transferProgress()
            transferView:playAction()
            FieldManager:setTransferring(true)
            NpcManager:hideAllNpcMark()
        else
            self.m_popupUi:removeUIByKey( "m_transferView" )
            FieldManager:setTransferring(false)
        end
    end,true)
end

-- 佣兵界面
function UiHandler:mecenaryUiVisibility(visible,isStory,returCallback, partnerId)
    if visible then
        if isStory then
            app:sendMsg("PartnerController", "openViewByStory", {returCallback = returCallback, partnerId = partnerId})
        else
            app:sendMsg("PartnerController", "openView", {returCallback = returCallback, partnerId = partnerId})
        end
    else
        app:sendMsg("PartnerController", "closeView")
    end
end

function UiHandler:showCountDown(params)
    local countDownView = self.m_storyModeUi:isCreateUi("m_countdownView")
    if not countDownView then
        local CountDownView = app:getClass("CountDownView")
        countDownView = CountDownView.new(params)
        self.m_storyModeUi:addUI("m_countdownView",countDownView)
    end
end

function UiHandler:removeCountDown()
    self.m_storyModeUi:removeUIByKey("m_countdownView")
end

-------------------- DoEventHandler start --------------------
function UiHandler:showInteractiveUi(npcId,returnCall)
    local interactiveView = self.m_storyModeUi:isCreateUi("m_interactiveView")
    if not interactiveView then
        local Interactive = app:getClass("NpcInteractive")
        interactiveView = Interactive.new(npcId,returnCall)
        self.m_storyModeUi:addUI("m_interactiveView",interactiveView)
    end
end

function UiHandler:hideInteractiveUi()
    self.m_storyModeUi:removeUIByKey("m_interactiveView")
end

-- 屏幕打字 DoEventHandler
function UiHandler:TypeWordsViewVisibility(visible,words,fontSize,delayTime,typeTime,overDelay,lineLen,color,typeOverCall)
    if visible then
        local typeWordsView = self.m_storyModeUi:isCreateUi("m_typeWordsView")

        if not typeWordsView then
            local TypeWordsView = app:getClass("TypeWordsView")
            typeWordsView = TypeWordsView.new(words,fontSize,delayTime,typeTime,overDelay,lineLen,color,typeOverCall)
            self.m_storyModeUi:addUI("m_typeWordsView",typeWordsView)
        else
            typeWordsView:setVisible(true)
        end
    else
        self.m_storyModeUi:removeUIByKey("m_typeWordsView")
    end
end

---
-- 显示战斗确认
--
function UiHandler:showBattleConfirm(okCall,cancelCall,isEscort)
    local battleConfirmController = self.m_storyModeUi:isCreateUi("m_battleConfirmController")
    if not battleConfirmController then
        local BattleConfirmController = app:getClass("BattleConfirmController")
        battleConfirmController = BattleConfirmController.new(isEscort)
        self.m_storyModeUi:addUI("m_battleConfirmController",battleConfirmController)
    else
        battleConfirmController:setVisible(true)
    end
    battleConfirmController:setOkCallback(okCall)
    battleConfirmController:setCancelCallback(cancelCall)
end

---
-- 隐藏战斗确认
--
function UiHandler:hideBattleConfirm()
    self.m_storyModeUi:removeUIByKey("m_battleConfirmController")
end

-- 屏幕渐变字 DoEventHandler
function UiHandler:fadeWordsViewVisibility(visible,params)
    if visible then
        local fadeWordsView = self.m_storyModeUi:isCreateUi("m_fadeWordsView")
        if not fadeWordsView then
            local FadeWordsView = app:getClass("FadeWordsView")
            fadeWordsView = FadeWordsView.new(params)
            self.m_storyModeUi:addUI("m_fadeWordsView",fadeWordsView)
        else
            fadeWordsView:setVisible(true)
        end
    else
        self.m_storyModeUi:removeUIByKey("m_fadeWordsView")
    end
end

-- 剧情分支 DoEventHandler
function UiHandler:storyBranchVisibility(visible,okCall,cancelCall)
    if visible then
        local storyBranch = self.m_storyModeUi:isCreateUi("m_storyBranch")
        if not storyBranch then
            local StoryBranch = app:getClass("StoryBranch")
            storyBranch = StoryBranch.new()
            self.m_storyModeUi:addUI("m_storyBranch",storyBranch)
        else
            storyBranch:setVisible(true)
        end
        storyBranch:setOkCall(okCall)
        storyBranch:setCancelCall(cancelCall)
    else
        self.m_storyModeUi:removeUIByKey("m_storyBranch")
    end
end

-- 心话视图 DoEventHandler
function UiHandler:HeartWordsViewVisibility(visible,content,time,showDirection,callback)
    if visible then
        local heartWordsView = self.m_storyModeUi:isCreateUi("m_heartWordsView")
        if not heartWordsView then
            local HeartWordsView = app:getClass("HeartWordsView")
            heartWordsView = HeartWordsView.new()
            self.m_storyModeUi:addUI("m_heartWordsView",heartWordsView)
        else
            heartWordsView:setVisible(true)
        end

        heartWordsView:setContent(content)
        heartWordsView:setHoldTime(time)
        heartWordsView:setShowDirection(showDirection)
        heartWordsView:setCallOver(callback)
        heartWordsView:appear()
    else
        self.m_storyModeUi:removeUIByKey("m_heartWordsView")
    end
end

-- 眨眼黑屏，用于过场
function UiHandler:showBlinkBlackScreen(time)
    if cc.isDead(self.m_uiParent) then return end
    time = time or 1
    local blackScreen = self._blackScreen
    if not blackScreen then
        blackScreen = self:createBlackMask()
        self.m_uiParent:addChild(blackScreen, SceneZOrder.blackSceenZorder)
        self._blackScreen = blackScreen
    end
    blackScreen:stopAllActions()
    blackScreen:setOpacity(0)
    local action = cca.seq({cca.show(), cca.fadeIn(time/2), cca.fadeOut(time/2), cca.hide()})
    blackScreen:runAction(action)
end

function UiHandler:showBlackScreenFadeout(time)
    if cc.isDead(self.m_uiParent) then return end
    time = time or 1
    local blackScreen = self._blackScreen
    if not blackScreen then
        blackScreen = self:createBlackMask()
        self.m_uiParent:addChild(blackScreen, SceneZOrder.blackSceenZorder)
        self._blackScreen = blackScreen
    end
    blackScreen:stopAllActions()
    blackScreen:setOpacity(255)
    local action = cca.seq({cca.show(), cca.fadeOut(time), cca.hide()})
    blackScreen:runAction(action)
end

--  DoEventHandler
function UiHandler:showBlackScreenMask()
    if not self._blackScreenMask then
        self._blackScreenMask = self:createBlackMask()
        self.m_storyModeUi:addUI(nil,self._blackScreenMask,true)
    end
end

function UiHandler:removeBlackScreenMask()
    if self._blackScreenMask then
        self._blackScreenMask:removeFromParent()
        self._blackScreenMask = nil
    end
end

function UiHandler:createBlackMask()
    local InsetsRect = cc.rect(5,5,5,5)
    local BlackScreenNode = ccui.Scale9Sprite:create(InsetsRect,Res.Public_Black_Img)
    BlackScreenNode:setContentSize(cc.size(display.width,display.height))
    BlackScreenNode:setAnchorPoint(cc.p(0,0))
    BlackScreenNode:setPosition(cc.p(0,0))
    BlackScreenNode:setName("BlackScreen")
    return BlackScreenNode
end

---
-- fadeFlag fadeIn fadeOut
--
function UiHandler:blackScreenFade(fadeFlag,time,callback,outStartCall)
    self.m_storyModeUi:openTouchMask()

    self.mBlackScreenFade = true
    if fadeFlag == "fadeIn" then
        if self.mBlackScreen then
            self.mBlackScreen:removeFromParent()
            self.mBlackScreen = nil
        end

        if not self.mBlackScreen then
            self.mBlackScreen = self:createBlackMask()
            self.m_storyModeUi:addUI(nil,self.mBlackScreen,true)
        end

        self.mBlackScreen:setOpacity(0)
        local function call()
            if callback then
                callback()
            end
            self.mBlackScreenFade = false
        end
        self.mBlackScreen:stopAllActions()
        if time == 0 then
            self.mBlackScreen:setOpacity(255)
            call()
        else
            local action = cc.Sequence:create(cc.FadeIn:create(time),cc.CallFunc:create(call))
            self.mBlackScreen:runAction(action)
        end
    elseif fadeFlag == "fadeOut" then
        local function outCall()
            if callback then
                callback()
            end
            self:closeStoryTouchMask()
            self.mBlackScreenFade = false
        end

        if self.mBlackScreen then
            self.mBlackScreen:setOpacity(255)
            local function call()
                if self.mBlackScreen then
                    self.mBlackScreen:removeFromParent()
                    self.mBlackScreen = nil
                    outCall()
                end
            end

            self.mBlackScreen:stopAllActions()
            if time == 0 then
                self.mBlackScreen:setOpacity(0)
                call()
            else
                local action = cc.Sequence:create(cc.FadeOut:create(time),cc.CallFunc:create(call))
                self.mBlackScreen:runAction(action)
            end
        else
            outCall()
        end

        if outStartCall then
            outStartCall()
        end

    end
end

function UiHandler:addVideo(videoLayer)
    if cc.isDead(self.m_uiParent) then return end
    if not videoLayer then return end
    self:removeVideo()
    videoLayer:setName("name_video_layer")
    self.m_uiParent:addChild(videoLayer,SceneZOrder.loadingZOrder + 1)
end

function UiHandler:removeVideo()
    if cc.isDead(self.m_uiParent) then return end
    self.m_uiParent:removeChildByName("name_video_layer")
end

function UiHandler:showGatherControl(gatherNpcId)
    if cc.isDead(self.m_uiParent) then return end
    if not self.m_gatherControlController then
        local GatherControlController = app:getClass("GatherControlController")
        self.m_gatherControlController = GatherControlController.new(gatherNpcId)
        self.m_gatherControlController:setName("GatherControlController")
        self.m_uiParent:addChild(self.m_gatherControlController,SceneZOrder.gatherControlZOrder)
        FieldManager:getMyCharacter():setGatherNode(self.m_gatherControlController)
    else
        self.m_gatherControlController:setVisible(true)
    end

    if DEBUG == -1 then
        self.m_gatherControlController:setVisible(false)
    end
end

function UiHandler:hideGatherControl()
    if cc.isDead(self.m_uiParent) then return end
    if self.m_gatherControlController then
        self.m_uiParent:removeChild(self.m_gatherControlController)
        self.m_gatherControlController = nil
        FieldManager:getMyCharacter():setGatherNode(nil)
    end
end

function UiHandler:setGatherControlTime(time)
    if self.m_gatherControlController then
        self.m_gatherControlController:setGatherTime(time)
    end
end

function UiHandler:setGatherOverCallback(callback)
    if self.m_gatherControlController then
        self.m_gatherControlController:setGatherOverCallback(callback)
    end
end

function UiHandler:setGatherControlProgress(curTimes,maxTimes)
    if self.m_gatherControlController then
        self.m_gatherControlController:setGatherControlProgress(curTimes,maxTimes)
    end
end

-------------------- DoEventHandler end --------------------

-- 弹出：屏幕右上角tips
function UiHandler:showThirdLevelTips( data )
    if not self._isInit then return end
    app:sendMsg("UIController", "showThirdLevelTips", data)
end

--------------->>>> 新版floattips
function UiHandler:showFloatPanel( dataTemp )
    local floatViewTemp = self.m_popupUi:isCreateUi("m_floatView")

    if self._lastTouchPositionX then
        dataTemp.params.fromX = self._lastTouchPositionX
    end
    if self._lastTouchPositionY then
        dataTemp.params.fromY = self._lastTouchPositionY
    end

    if floatViewTemp then
        floatViewTemp:setLocalZOrder( 9999 )
        floatViewTemp:setVisible(true)
        floatViewTemp:refreshContent( dataTemp.params )
        -- floatViewTemp:adjustPos()
    else
        local newFloatTipsView = require("app.newFloatTips.newFloatTipsView")
        local floatViewTemp = newFloatTipsView.new( dataTemp.params )
        self.m_popupUi:addUI("m_floatView", floatViewTemp, true)
        -- floatViewTemp:adjustPos()
    end
end
function UiHandler:hideFloatPanel()
    local floatViewTemp = self.m_popupUi:isCreateUi("m_floatView")
    if floatViewTemp then
        floatViewTemp:setLocalZOrder( -1 )
        floatViewTemp:hide()
    end
end

function UiHandler:addFloatFrameListener()
    --通用悬浮框监听
    local function openFloatListener(event)
        if not event or not event._usedata then return end
        -- if BattleManager:isInBattle() then return end
        self:showFloatPanel(event._usedata)
    end
    local function closeFloatListener(event)
        self:hideFloatPanel()
    end
    app:addCustomEventListener("EVENT_OPEN_FLOAT",openFloatListener,self.m_uiParent)
    app:addCustomEventListener("EVENT_CLOSE_FLOAT",closeFloatListener,self.m_uiParent)
end

function UiHandler:showItemTips(itemData, parent, closeCB)
    local type = itemData.itemBagType
    local data = itemData

    local param = { itemId=tonumber(data.tid) }
    local tipsType
    if type == Enums.ItemBagType.daibi then
        tipsType = Enums.TipsType.daibi
    elseif type == Enums.ItemBagType.mount then
        tipsType = Enums.TipsType.mount
    elseif type == Enums.ItemBagType.equip then
        tipsType = Enums.TipsType.equip
    elseif type == Enums.ItemBagType.jewel then
        tipsType = Enums.TipsType.jewel
    elseif type == Enums.ItemBagType.fame then -- 声望的tips当代币处理
        param.itemId = tonumber(data.uid)
        tipsType = Enums.TipsType.fame
    elseif type == Enums.ItemBagType.mountSoul then
        param.itemId = tonumber(data.id)
        tipsType = Enums.TipsType.mountSoul
    else
        tipsType = Enums.TipsType.item
    end

    param.dataTemp = data
    param.tipsType = tipsType
    param.unShowOrigin = self._unShowOrigin
    param.closeCallBack = function()
        -- if not tolua.isnull( self ) then
        --     self:setSelected(false)
        -- end
        if closeCB then
            closeCB()
        end
    end
    local boundingBoxTemp = parent:getBoundingBox()
    local worldPosTemp = parent:getParent():convertToWorldSpace( cc.p( boundingBoxTemp.x, boundingBoxTemp.y ) )
    boundingBoxTemp.x = worldPosTemp.x
    boundingBoxTemp.y = worldPosTemp.y
    param.boundingBox = boundingBoxTemp
    app:dispatchCustomEvent("EVENT_OPEN_FLOAT", {params=param})
end

-- 地下城掉落
function UiHandler:showDungeonDrop(loots, rewardLimit, extra)
    self:removeDungeonDrop()

    local DungeonDropView = require("app.system.dungeondrop.DungeonDropView")
    local view = DungeonDropView.new()
    view:onCloseView(handler(self, self.removeDungeonDrop))
    view:show()
    view:setDrops(loots, rewardLimit, extra)

    self:addPopupUi(view, "m_dungeonDrop")
end

function UiHandler:removeDungeonDrop()
    self:removePopupUiByKey("m_dungeonDrop")
end

---
-- 显示玩家头顶菜单
--
function UiHandler:showHeadMenu(params)
    app:sendMsg("HeadMenuController", "showView", params)
end

function UiHandler:hideHeadMenu()
    app:sendMsg("HeadMenuController", "hideView")
end

-- 抛出消息，根据配置 飘字／弹框
-- msgId        消息id（可以是Message取配置），或者string表id
-- params       填充消息数据
-- cbs          回调table，{ok=func, cancel=func}
-- tag          pushToast 的tag
function UiHandler:showMessage(msgId, params, cbs, tag)
    local msgConfig = GD:getMessageConfig(msgId)
    local msgNode = nil
    if msgConfig then
        local msgType = tonumber(msgConfig.type)
        local message = L(msgConfig.msgId)
        if params then
            message = string.format(message, unpack(params))
        end

        if msgType == 1 then
            display.pushToast(message, tag)
        elseif msgType == 2 then
            self.m_uiParent:endCharacterMove(nil,true)
            msgNode = display.newMessageBox(message, cbs and cbs.ok)
        elseif msgType == 3 then
            self.m_uiParent:endCharacterMove(nil,true)
            msgNode = display.newConfirmDialog(message, cbs and cbs.ok, cbs and cbs.cancel)
        end
        if msgNode then
            self.m_systemMsgUi:addUI(nil,msgNode)
        end
    else
        --如果没有这个id，则原样显示
        if params and params.pushToast then
            display.pushToast(L(msgId), tag)
        else
            self.m_uiParent:endCharacterMove(nil,true)
            msgNode = display.newMessageBox(L(msgId), cbs and cbs.ok)
        end
        if msgNode then
            self.m_systemMsgUi:addUI(nil,msgNode)
        end
    end
end

function UiHandler:isDesktopShow()
    return self._desktopController:isVisible()
end

function UiHandler:showDesktop()
    -- print(debug.traceback("UiHandler:showDesktop", 1))
    if not app:isBattleGuideComp() then return end
    if not Config.uiDisplay then return end
    if self:isDesktopShow() then return end
    if BattleManager:isBattle() then return end
    if StoryManager:isEnterStoryMode() then return end
    -- 星空谜棋, 歌剧院不显示desktop
    if app:sendMsg("ChessModel", "isChessMap") then return end
    if app:sendMsg("TheatreModel", "isTheatreMap") then return end

    self._desktopController:show()
    app:sendMsg("PlayerController", "showExpBar")
    app:sendMsg("UIController", "showQuickView")
    app:sendMsg("DynastyMapController", "showDynastyMapView")
    self:showChatUI()
    --self:checkPayNotice()
end

function UiHandler:hideDesktop()
    self._desktopController:setVisible(false)
    app:sendMsg("PlayerController", "hideExpBar")
    app:sendMsg("UIController", "hideQuickView")
    app:sendMsg("DynastyMapController", "hideDynastyMapView")
    self:hideChatUI()
end

-- 设置主界面右下角提示visible
function UiHandler:setDesktopTipVisible(b)
    -- 如果在地下城内不显示
    if b and DungeonManager:isInDungeon() then
        b = not b
    end
    self._desktopController:setDesktopTipVisible(b)
end

function UiHandler:getDesktopController()
    return self._desktopController
end

function UiHandler:checkDesktopGuide()
    if self:isHaveUI() then return end

    self._desktopController:checkGuide()
end

-- 设置主界面广告弹窗节点visible
function UiHandler:setDesktopAdvertVisible(b)
    self._desktopController:setDesktopAdvertNodeVisible(b)
end

function UiHandler:checkPayNotice()
    if self:isHaveUI() then return end
    local RewardModel = app:getInst("RewardModel")
    -- 付费弹窗(首充：条件是通关地下城)
    if DungeonManager:getPassDungeonState() and not DungeonManager:isInDungeon() then
        local payNoticeSubType = RewardModel:popUpPayNoticeActivity()
        if payNoticeSubType == Enums.ActivitySubType.FirstRecharge and RewardModel:checkPopUpTimesBySubType(payNoticeSubType) then
            app:sendMsg("RewardController", "openPayNoticeView", payNoticeSubType)
            local allTimes = UD:getValueFromGenericByKey("payNoticeAllTimes"..payNoticeSubType) or 0
            UD:saveGeneric("payNoticeAllTimes"..payNoticeSubType, tonumber(allTimes)+1)
        end
    end
    
    -- 付费弹窗(基金：条件是抽奖)
    if app:getInst("MallModel"):getDrawState() then
        local payNoticeSubType = RewardModel:popUpPayNoticeActivity()
        if payNoticeSubType == Enums.ActivitySubType.Fund and RewardModel:checkPopUpTimesBySubType(payNoticeSubType) then
            app:sendMsg("RewardController", "openPayNoticeView", payNoticeSubType)
            local allTimes = UD:getValueFromGenericByKey("payNoticeAllTimes"..payNoticeSubType) or 0
            UD:saveGeneric("payNoticeAllTimes"..payNoticeSubType, tonumber(allTimes)+1)
        end
    end
end

function UiHandler:showChatUI()
    if not app:isBattleGuideComp() then return end
    if StoryManager:isEnterStoryMode() then return end

    if self:isFunctionOpen(Constant.FUNC_TYPE_CHAT) then
        -- 已经在显示了就不需要重复显示，因为每次点击地图都会show一次（需要被优化的调用）
        local ctrl = app:getInst("IMSimpleController")
        if not ctrl then return end
        if not ctrl:hasView() or not ctrl:isViewVisible() then
            app:sendMsg("IMSimpleController", "showView")
        end
    end
end

function UiHandler:hideChatUI()
    app:sendMsg("IMSimpleController", "hideView")
end

function UiHandler:showArenaVs(data)
    -- dump(data, "showArenaVs")
    if self._arenaVs then return end
    local ArenaVs = app:getClass("ArenaVs")
    self._arenaVs = ArenaVs.new()
    self._arenaVs:update(data)
    self.m_uiParent:addChild(self._arenaVs,SceneZOrder.loadingZOrder + 1)

    -- vs界面25秒超时，超时后主动移除
    self._arenaVs:performWithDelay(function()
        self:hideArenaVs()
    end, 25)
end

function UiHandler:hideArenaVsNotice()
    if not self._arenaVs then return end
    self._arenaVs:hideNoticeTips()
end

function UiHandler:hideArenaVs()
    if not self._arenaVs then return end
    self.m_uiParent:removeChild(self._arenaVs)
    self._arenaVs = nil
end

function UiHandler:getArenaVsLoading()
    return self._arenaVs
end

---------------------------- touchLayer start -------------------------------
function UiHandler:addPrepareBattleTouchMask()
    self:removePrepareBattleTouchMask()

    self._prepareBattleTouchLayer = display.newTouchLayer()
    self._prepareBattleTouchLayer:setName("PrepareBattleTouchLayer")
    self.m_uiParent:addChild(self._prepareBattleTouchLayer,SceneZOrder.battleLayerZOrder + 1)
end

function UiHandler:removePrepareBattleTouchMask()
    if self._prepareBattleTouchLayer then
        self.m_uiParent:removeChild(self._prepareBattleTouchLayer)
        self._prepareBattleTouchLayer = nil
    end
end

function UiHandler:disableMainTaskTrackingTouch()
    if cc.isAlive(self._desktopController)
      and cc.isAlive(self._desktopController:getTaskTrackController())
      and cc.isAlive(self._desktopController:getTaskTrackController():getMainTaskTrackView())
      and cc.isAlive(self._desktopController:getTaskTrackController():getMainTaskTrackView():getMainTaskTrackRender()) then
        self._desktopController:getTaskTrackController():getMainTaskTrackView():getMainTaskTrackRender():disableTouch()
    end
end

function UiHandler:enableMainTaskTrackingTouch()
    if DoEventHandler.isTaskMaskFlag() then return end

    if cc.isAlive(self._desktopController)
      and cc.isAlive(self._desktopController:getTaskTrackController())
      and cc.isAlive(self._desktopController:getTaskTrackController():getMainTaskTrackView())
      and cc.isAlive(self._desktopController:getTaskTrackController():getMainTaskTrackView():getMainTaskTrackRender()) then
        self._desktopController:getTaskTrackController():getMainTaskTrackView():getMainTaskTrackRender():enableTouch()
    end
end

function UiHandler:addTopTouchMask(callback)
    if not self._topTouchLayer then
        self._topTouchLayer = display.newNode()
        self._topTouchLayer:setContentSize(display.width, display.height)
        self._topTouchLayer:setName("TopTouchLayer")
        self.m_uiParent:addChild(self._topTouchLayer,SceneZOrder.taskingTouchZOrder)
        local function touchBegan(touch, event)
            if callback then
                callback(touch)
            end
            return true
        end
        local touchListener = cc.EventListenerTouchOneByOne:create()
        touchListener:setSwallowTouches(true)
        touchListener:registerScriptHandler(touchBegan,cc.Handler.EVENT_TOUCH_BEGAN)
        cc.Director:getInstance():getEventDispatcher():addEventListenerWithSceneGraphPriority(touchListener, self._topTouchLayer)
    end
end

function UiHandler:removeTopTouchMask()
    if self._topTouchLayer then
        self.m_uiParent:removeChild(self._topTouchLayer)
        self._topTouchLayer = nil
    end
end

function UiHandler:clearTouchMask()
    self:enableMainTaskTrackingTouch()
    self:removePrepareBattleTouchMask()
end

function UiHandler:closeStoryTouchMask()
    if self.m_storyModeUi then
        self.m_storyModeUi:closeTouchMask()
    end
end

-- 设置主线任务特效(切换地图 和 主线任务ID变化时 调用)
function UiHandler:updateMainTaskEffect()
    if self.m_mainEffect then
        self.m_mainEffect:removeFromParent()
        self.m_mainEffect = nil
    end
    FieldManager:playMyMainTaskEffect()
    local mapId = MapManager:getMapId()
    local task= UD:getMainTask()
    if not mapId or not task then return end

    local taskConfig = task:getConfig()
    if not taskConfig then return end

    -- UI特效
    if taskConfig.filterCreate then
        local arrValue = string.split(taskConfig.filterCreate, "|")
        if #arrValue == 3 then
            local targetMapId = tonumber(arrValue[1])
            local armatureName = tostring(arrValue[2])
            local animationName = tostring(arrValue[3])
        
            if targetMapId == mapId then
                local params = {
                    path = Res.ArmatureEffectPath .. armatureName,
                    armatureName = armatureName,
                    animationName = animationName,
                    skeletonName = armatureName,
                }
            
                local Armature = app:getClass("Armature")
                local armature = Armature.create(params)
                armature:play(params.animationName) -- 循环播放暂时有bug，这里填一个比较大的次数
                armature:setPosition(cc.p(display.safe_width / 2, display.cy))
                self.m_uiParent:addChild(armature, SceneZOrder.gatherControlZOrder) -- 添加到UI下层
                -- self:addPopupUi(armature)
                self.m_mainEffect = armature
            end
        end
    end

    -- 人物身上显示特效
    if taskConfig.effectCreate then
        local arrValue = string.split(taskConfig.effectCreate, "|")
        if #arrValue == 2 then
            local targetMapId = tonumber(arrValue[1])
            local buffName = tostring(arrValue[2])

            if targetMapId == mapId then
                FieldManager:playMyMainTaskEffect(buffName)
            end
        end
    end
    
end
---------------------------- touchLayer end -------------------------------

return UiHandler
